package demo;

import java.nio.charset.StandardCharsets;

public class Demo04 {
    public static void main(String[] args) {
        /*
         * 如果字符的编码在 128 ~ 2047 范围，采用2字节编码
         */
        System.out.println("α的Unicode编码：");
        String str = "α";
        System.out.println((int)str.charAt(0));
        System.out.println(Integer.toBinaryString(str.charAt(0)));

        System.out.println("双字节UTF-8编码：");
        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
        System.out.println("len:"+bytes.length);
        //                                        byte->int
        System.out.println(Integer.toBinaryString(bytes[0] & 0xff));
        System.out.println(Integer.toBinaryString(bytes[1] & 0xff));
    }
}
